home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / bash-108.zoo / bash-1.08 / readline / doc / history.info < prev    next >
Encoding:
Text File  |  1991-05-01  |  17.5 KB  |  519 lines

  1. Info file history.info, produced by Makeinfo, -*- Text -*- from input
  2. file hist.texinfo.
  3.  
  4.    This document describes the GNU History library, a programming
  5. tool that provides a consistent user interface for recalling lines
  6. of previously typed input.
  7.  
  8.    Copyright (C) 1988, 1991 Free Software Foundation, Inc.
  9.  
  10.    Permission is granted to make and distribute verbatim copies of
  11. this manual provided the copyright notice and this permission notice
  12. pare preserved on all copies.
  13.  
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided that
  16. the entire resulting derived work is distributed under the terms of
  17. a permission notice identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for
  21. modified versions, except that this permission notice may be stated
  22. in a translation approved by the Foundation.
  23.  
  24. File: history.info,  Node: Top,  Next: Using History Interactively,  Prev: (DIR),  Up: (DIR)
  25.  
  26. GNU History Library
  27. *******************
  28.  
  29.    This document describes the GNU History library, a programming
  30. tool that provides a consistent user interface for recalling lines
  31. of previously typed input.
  32.  
  33. * Menu:
  34.  
  35. * Using History Interactively::      GNU History User's Manual.
  36. * Programming with GNU History::  GNU History Programmer's Manual.
  37. * Concept Index::          Index of concepts described in this manual.
  38. * Function and Variable Index::      Index of externally visible functions
  39.                   and variables.
  40.  
  41. File: history.info,  Node: Using History Interactively,  Next: Programming with GNU History,  Prev: Top,  Up: Top
  42.  
  43. Using History Interactively
  44. ***************************
  45.  
  46.    This chapter describes how to use the GNU History Library
  47. interactively, from a user's standpoint.  It should be considered a
  48. user's guide.  For information on using the GNU History Library in
  49. your own programs, *note Programming with GNU History::..
  50.  
  51. * Menu:
  52.  
  53. * History Interaction::        What it feels like using History as a user.
  54.  
  55. File: history.info,  Node: History Interaction,  Up: Using History Interactively
  56.  
  57. History Interaction
  58. ===================
  59.  
  60.    The History library provides a history expansion feature that is
  61. similar to the history expansion in Csh.  The following text
  62. describes the sytax that you use to manipulate the history
  63. information.
  64.  
  65.    History expansion takes place in two parts.  The first is to
  66. determine which line from the previous history should be used during
  67. substitution.  The second is to select portions of that line for
  68. inclusion into the current one.  The line selected from the previous
  69. history is called the "event", and the portions of that line that
  70. are acted upon are called "words".  The line is broken into words
  71. in the same fashion that the Bash shell does, so that several
  72. English (or Unix) words surrounded by quotes are considered as one
  73. word.
  74.  
  75. * Menu:
  76.  
  77. * Event Designators::    How to specify which history line to use.
  78. * Word Designators::    Specifying which words are of interest.
  79. * Modifiers::        Modifying the results of susbstitution.
  80.  
  81. File: history.info,  Node: Event Designators,  Next: Word Designators,  Up: History Interaction
  82.  
  83. Event Designators
  84. -----------------
  85.  
  86.    An event designator is a reference to a command line entry in the
  87. history list.
  88.  
  89. `!'
  90.      Start a history subsititution, except when followed by a space,
  91.      tab, or the end of the line... = or (.
  92.  
  93. `!!'
  94.      Refer to the previous command.  This is a synonym for `!-1'.
  95.  
  96. `!n'
  97.      Refer to command line N.
  98.  
  99. `!-n'
  100.      Refer to the command line N lines back.
  101.  
  102. `!string'
  103.      Refer to the most recent command starting with STRING.
  104.  
  105. `!?string'[`?']
  106.      Refer to the most recent command containing STRING.
  107.  
  108. File: history.info,  Node: Word Designators,  Next: Modifiers,  Prev: Event Designators,  Up: History Interaction
  109.  
  110. Word Designators
  111. ----------------
  112.  
  113.    A : separates the event specification from the word designator. 
  114. It can be omitted if the word designator begins with a ^, $, * or %.
  115. Words are numbered from the beginning of the line, with the first
  116. word being denoted by a 0 (zero).
  117.  
  118. `0 (zero)'
  119.      The zero'th word.  For many applications, this is the command
  120.      word.
  121.  
  122. `n'
  123.      The N'th word.
  124.  
  125. `^'
  126.      The first argument.  that is, word 1.
  127.  
  128. `$'
  129.      The last argument.
  130.  
  131. `%'
  132.      The word matched by the most recent `?string?' search.
  133.  
  134. `x-y'
  135.      A range of words; `-Y' Abbreviates `0-Y'.
  136.  
  137. `*'
  138.      All of the words, excepting the zero'th.  This is a synonym for
  139.      `1-$'.  It is not an error to use * if there is just one word
  140.      in the event.  The empty string is returned in that case.
  141.  
  142. File: history.info,  Node: Modifiers,  Prev: Word Designators,  Up: History Interaction
  143.  
  144. Modifiers
  145. ---------
  146.  
  147.    After the optional word designator, you can add a sequence of one
  148. or more of the following modifiers, each preceded by a :.
  149.  
  150. `#'
  151.      The entire command line typed so far.  This means the current
  152.      command, not the previous command, so it really isn't a word
  153.      designator, and doesn't belong in this section.
  154.  
  155. `h'
  156.      Remove a trailing pathname component, leaving only the head.
  157.  
  158. `r'
  159.      Remove a trailing suffix of the form `.'SUFFIX, leaving the
  160.      basename.
  161.  
  162. `e'
  163.      Remove all but the suffix.
  164.  
  165. `t'
  166.      Remove all leading  pathname  components, leaving the tail.
  167.  
  168. `p'
  169.      Print the new command but do not execute it.
  170.  
  171. File: history.info,  Node: Programming with GNU History,  Next: Concept Index,  Prev: Using History Interactively,  Up: Top
  172.  
  173. Programming with GNU History
  174. ****************************
  175.  
  176.    This chapter describes how to interface the GNU History Library
  177. with programs that you write.  It should be considered a technical
  178. guide.  For information on the interactive use of GNU History, *note
  179. Using History Interactively::..
  180.  
  181. * Menu:
  182.  
  183. * Introduction to History::    What is the GNU History library for?
  184. * History Storage::        How information is stored.
  185. * History Functions::        Functions that you can use.
  186. * History Variables::        Variables that control behaviour.
  187. * History Programming Example::    Example of using the GNU History Library.
  188.  
  189. File: history.info,  Node: Introduction to History,  Next: History Storage,  Up: Programming with GNU History
  190.  
  191. Introduction to History
  192. =======================
  193.  
  194.    Many programs read input from the user a line at a time.  The GNU
  195. history library is able to keep track of those lines, associate
  196. arbitrary data with each line, and utilize information from previous
  197. lines in making up new ones.
  198.  
  199.    The programmer using the History library has available to him
  200. functions for remembering lines on a history stack, associating
  201. arbitrary data with a line, removing lines from the stack, searching
  202. through the stack for a line containing an arbitrary text string,
  203. and referencing any line on the stack directly.  In addition, a
  204. history "expansion" function is available which provides for a
  205. consistent
  206. user interface across many different programs.
  207.  
  208.    The end-user using programs written with the History library has
  209. the benifit of a consistent user interface, with a set of well-known
  210. commands for manipulating the text of previous lines and using that
  211. text in new commands.  The basic history manipulation commands are
  212. similar to the history substitution used by `Csh'.
  213.  
  214.    If the programmer desires, he can use the Readline library, which
  215. includes some history manipulation by default, and has the added
  216. advantage of Emacs style command line editing.
  217.  
  218. File: history.info,  Node: History Storage,  Next: History Functions,  Prev: Introduction to History,  Up: Programming with GNU History
  219.  
  220. History Storage
  221. ===============
  222.  
  223.      typedef struct _hist_entry {
  224.        char *line;
  225.        char *data;
  226.      } HIST_ENTRY;
  227.  
  228. File: history.info,  Node: History Functions,  Next: History Variables,  Prev: History Storage,  Up: Programming with GNU History
  229.  
  230. History Functions
  231. =================
  232.  
  233.    This section describes the calling sequence for the various
  234. functions present in GNU History.
  235.  
  236.  * Function: void using_history ()
  237.      Begin a session in which the history functions might be used. 
  238.      This just initializes the interactive variables.
  239.  
  240.  * Function: void add_history (CHAR *STRING)
  241.      Place STRING at the end of the history list.  The associated
  242.      data field (if any) is set to `NULL'.
  243.  
  244.  * Function: int where_history ()
  245.      Returns the number which says what history element we are now
  246.      looking at.
  247.  
  248.  * Function: int history_set_pos (INT POS)
  249.      Set the position in the history list to POS.
  250.  
  251.  * Function: int history_search_pos (CHAR *STRING, INT DIRECTION, INT
  252.           POS)
  253.      Search for STRING in the history list, starting at POS, an
  254.      absolute index into the list.  DIRECTION, if negative, says to
  255.      search backwards from POS, else forwards.  Returns the absolute
  256.      index of the history element where STRING was found, or -1
  257.      otherwise.
  258.  
  259.  * Function: HIST_ENTRY *remove_history ();
  260.      Remove history element WHICH from the history.  The removed
  261.      element is returned to you so you can free the line, data, and
  262.      containing structure.
  263.  
  264.  * Function: void stifle_history (INT MAX)
  265.      Stifle the history list, remembering only MAX number of entries.
  266.  
  267.  * Function: int unstifle_history ();
  268.      Stop stifling the history.  This returns the previous amount the
  269.      history was stifled by.  The value is positive if the history
  270.      was stifled, negative if it wasn't.
  271.  
  272.  * Function: int read_history (CHAR *FILENAME)
  273.      Add the contents of FILENAME to the history list, a line at a
  274.      time.  If FILENAME is `NULL', then read from `~/.history'. 
  275.      Returns 0 if successful, or errno if not.
  276.  
  277.  * Function: int read_history_range (CHAR *FILENAME, INT FROM, INT TO)
  278.      Read a range of lines from FILENAME, adding them to the history
  279.      list.  Start reading at the FROM'th line and end at the TO'th. 
  280.      If FROM is zero, start at the beginning.  If TO is less than
  281.      FROM, then read until the end of the file.  If FILENAME is
  282.      `NULL', then read from `~/.history'.  Returns 0 if successful,
  283.      or `errno' if not.
  284.  
  285.  * Function: int write_history (CHAR *FILENAME)
  286.      Append the current history to FILENAME.  If FILENAME is `NULL',
  287.      then append the history list to `~/.history'.  Values returned
  288.      are as in `read_history ()'.
  289.  
  290.  * Function: int append_history (INT NELEMENTS, CHAR *FILENAME)
  291.      Append NELEMENT entries to FILENAME.  The entries appended are
  292.      from the end of the list minus NELEMENTS up to the end of the
  293.      list.
  294.  
  295.  * Function: HIST_ENTRY *replace_history_entry ()
  296.      Make the history entry at WHICH have LINE and DATA.  This
  297.      returns the old entry so you can dispose of the data.  In the
  298.      case of an invalid WHICH, a `NULL' pointer is returned.
  299.  
  300.  * Function: HIST_ENTRY *current_history ()
  301.      Return the history entry at the current position, as determined
  302.      by `history_offset'.  If there is no entry there, return a
  303.      `NULL' pointer.
  304.  
  305.  * Function: HIST_ENTRY *previous_history ()
  306.      Back up HISTORY_OFFSET to the previous history entry, and return
  307.      a pointer to that entry.  If there is no previous entry, return
  308.      a `NULL' pointer.
  309.  
  310.  * Function: HIST_ENTRY *next_history ()
  311.      Move `history_offset' forward to the next history entry, and
  312.      return the a pointer to that entry.  If there is no next entry,
  313.      return a `NULL' pointer.
  314.  
  315.  * Function: HIST_ENTRY **history_list ()
  316.      Return a `NULL' terminated array of `HIST_ENTRY' which is the
  317.      current input history.  Element 0 of this list is the beginning
  318.      of time.  If there is no history, return `NULL'.
  319.  
  320.  * Function: int history_search (CHAR *STRING, INT DIRECTION)
  321.      Search the history for STRING, starting at `history_offset'.  If
  322.      DIRECTION < 0, then the search is through previous entries,
  323.      else through subsequent.  If STRING is found, then
  324.      `current_history ()' is the history entry, and the value of
  325.      this function is the offset in the line of that history entry
  326.      that the STRING was found in.  Otherwise, nothing is changed,
  327.      and a -1 is returned.
  328.  
  329.  * Function: int history_expand (CHAR *STRING, CHAR **OUTPUT)
  330.      Expand STRING, placing the result into OUTPUT, a pointer to a
  331.      string.  Returns:
  332.  
  333.     `0'
  334.           If no expansions took place (or, if the only change in the
  335.           text was the de-slashifying of the history expansion
  336.           character),
  337.  
  338.     `1'
  339.           if expansions did take place, or
  340.  
  341.     `-1'
  342.           if there was an error in expansion.
  343.  
  344.      If an error ocurred in expansion, then OUTPUT contains a
  345.      descriptive error message.
  346.  
  347.  * Function: char *history_arg_extract (INT FIRST, INT LAST, CHAR
  348.           *STRING)
  349.      Extract a string segment consisting of the FIRST through LAST
  350.      arguments present in STRING.  Arguments are broken up as in the
  351.      GNU Bash shell.
  352.  
  353.  * Function: int history_total_bytes ();
  354.      Return the number of bytes that the primary history entries are
  355.      using.  This just adds up the lengths of `the_history->lines'.
  356.  
  357. File: history.info,  Node: History Variables,  Next: History Programming Example,  Prev: History Functions,  Up: Programming with GNU History
  358.  
  359. History Variables
  360. =================
  361.  
  362.    This section describes the variables in GNU History that are
  363. externally visible.
  364.  
  365.  * Variable: int history_base
  366.      For convenience only.  You set this when interpreting history
  367.      commands.  It is the logical offset of the first history element.
  368.  
  369. File: history.info,  Node: History Programming Example,  Prev: History Variables,  Up: Programming with GNU History
  370.  
  371. History Programming Example
  372. ===========================
  373.  
  374.    The following snippet of code demonstrates simple use of the GNU
  375. History Library.
  376.  
  377.      main ()
  378.      {
  379.        char line[1024], *t;
  380.        int done = 0;
  381.      
  382.        line[0] = 0;
  383.      
  384.        while (!done)
  385.          {
  386.            fprintf (stdout, "history%% ");
  387.            t = gets (line);
  388.      
  389.            if (!t)
  390.              strcpy (line, "quit");
  391.      
  392.            if (line[0])
  393.              {
  394.                char *expansion;
  395.                int result;
  396.      
  397.                using_history ();
  398.      
  399.                result = history_expand (line, &expansion);
  400.                strcpy (line, expansion);
  401.                free (expansion);
  402.                if (result)
  403.                  fprintf (stderr, "%s\n", line);
  404.      
  405.                if (result < 0)
  406.                  continue;
  407.      
  408.                add_history (line);
  409.              }
  410.      
  411.            if (strcmp (line, "quit") == 0) done = 1;
  412.            if (strcmp (line, "save") == 0) write_history (0);
  413.            if (strcmp (line, "read") == 0) read_history (0);
  414.            if (strcmp (line, "list") == 0)
  415.              {
  416.                register HIST_ENTRY **the_list = history_list ();
  417.                register int i;
  418.      
  419.                if (the_list)
  420.                  for (i = 0; the_list[i]; i++)
  421.                    fprintf (stdout, "%d: %s\n",
  422.                       i + history_base, the_list[i]->line);
  423.              }
  424.            if (strncmp (line, "delete", strlen ("delete")) == 0)
  425.              {
  426.                int which;
  427.                if ((sscanf (line + strlen ("delete"), "%d", &which)) == 1)
  428.                  {
  429.                    HIST_ENTRY *entry = remove_history (which);
  430.                    if (!entry)
  431.                      fprintf (stderr, "No such entry %d\n", which);
  432.                    else
  433.                      {
  434.                        free (entry->line);
  435.                        free (entry);
  436.                      }
  437.                  }
  438.                else
  439.                  {
  440.                    fprintf (stderr, "non-numeric arg given to `delete'\n");
  441.                  }
  442.              }
  443.          }
  444.      }
  445.  
  446. File: history.info,  Node: Concept Index,  Next: Function and Variable Index,  Prev: Programming with GNU History,  Up: Top
  447.  
  448. Concept Index
  449. *************
  450.  
  451. * Menu:
  452.  
  453. * event designators:                    Event Designators.
  454. * expansion:                            History Interaction.
  455.  
  456. File: history.info,  Node: Function and Variable Index,  Prev: Concept Index,  Up: Top
  457.  
  458. Function and Variable Index
  459. ***************************
  460.  
  461. * Menu:
  462.  
  463. * HIST_ENTRY **history_list:            History Functions.
  464. * HIST_ENTRY *current_history:          History Functions.
  465. * HIST_ENTRY *next_history:             History Functions.
  466. * HIST_ENTRY *previous_history:         History Functions.
  467. * HIST_ENTRY *remove_history:           History Functions.
  468. * HIST_ENTRY *replace_history_entry:    History Functions.
  469. * char *history_arg_extract:            History Functions.
  470. * int append_history:                   History Functions.
  471. * int history_base:                     History Variables.
  472. * int history_expand:                   History Functions.
  473. * int history_search:                   History Functions.
  474. * int history_search_pos:               History Functions.
  475. * int history_set_pos:                  History Functions.
  476. * int history_total_bytes:              History Functions.
  477. * int read_history:                     History Functions.
  478. * int read_history_range:               History Functions.
  479. * int unstifle_history:                 History Functions.
  480. * int where_history:                    History Functions.
  481. * int write_history:                    History Functions.
  482. * void add_history:                     History Functions.
  483. * void stifle_history:                  History Functions.
  484. * void using_history:                   History Functions.
  485.  
  486.  
  487. Tag Table:
  488. Node: Top973
  489. Node: Using History Interactively1567
  490. Node: History Interaction2075
  491. Node: Event Designators3127
  492. Node: Word Designators3770
  493. Node: Modifiers4675
  494. Node: Programming with GNU History5424
  495. Node: Introduction to History6151
  496. Node: History Storage7501
  497. Node: History Functions7765
  498. Node: History Variables13062
  499. Node: History Programming Example13498
  500. Node: Concept Index15743
  501. Node: Function and Variable Index16029
  502. End Tag Table
  503.